package com.pingguopifa.domain;

import com.pingguopifa.exception.ErrMessage;
import com.pingguopifa.exception.PingGuoException;

public enum UserRole {

	ROLE_ADMIN("0", "ROLE_ADMIN"),
	ROLE_USER("1", "ROLE_USER");
	
	private String code;
	private String roleName;

	private UserRole(String code, String roleName) {
		this.code = code;
		this.roleName = roleName;
	}

	public static UserRole getUserRoleByCode(String code) throws PingGuoException {
		for (UserRole value : values()) {
			if (value.getCode().equals(code)) {
				return value;
			}
		}
		throw new PingGuoException(ErrMessage.BAD_ROLE);
	}

	public static UserRole getUserRoleByRoleName(String clientName) throws PingGuoException {
		for (UserRole value : values()) {
			if (value.getRoleName().equals(clientName)) {
				return value;
			}
		}
		throw new PingGuoException(ErrMessage.BAD_ROLE);
	}

	public String getCode() {
		return code;
	}

	public String getRoleName() {
		return roleName;
	}
	
}
